package inventory.reports.view;

import inventory.reports.controller.CurrentStockReportController;
import inventory.reports.controller.InwardReportController;
import inventory.reports.controller.OutwardReportController;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;
import javax.swing.JLabel;

import utility.ViewUtilities;
import viewframework.UIFrameWork;

import java.awt.Font;
import java.awt.Dimension;
import java.awt.SystemColor;

public class ReportsMainView extends JPanel implements MouseListener 
{
	private JLabel lblCurrentStock;
	private JLabel lblOutwardReport;
	private JLabel lblInwardReport;
	private JLabel[]leftMenu;
	private JToolBar toolBar;
	private SpringLayout sl;
	
	public ReportsMainView() 
	{
		sl = new SpringLayout();
		setLayout(sl);
		setSize(1050,550);
			
		toolBar = new JToolBar();
		toolBar.setBackground(SystemColor.inactiveCaption);
		toolBar.setBorder(null);
		toolBar.setOrientation(SwingConstants.VERTICAL);
		sl.putConstraint(sl.SOUTH, toolBar, 0, sl.SOUTH, this);
		sl.putConstraint(sl.NORTH, toolBar, 1, sl.NORTH, this);
		sl.putConstraint(sl.WEST, toolBar, 0, sl.WEST, this);
		sl.putConstraint(sl.EAST, toolBar, 180, sl.WEST, this);
		makeLeftMenu();
		addButtonsInToolBar();
		addButtonListener();
		add(toolBar);
	}
	
	
	
	private void makeLeftMenu()
	{
		leftMenu=new JLabel[3];
		
		lblCurrentStock=new JLabel("Current Stock",SwingConstants.CENTER);
		lblCurrentStock.setPreferredSize(new Dimension(72, 40));
		lblCurrentStock.setMinimumSize(new Dimension(180, 40));
		lblCurrentStock.setMaximumSize(new Dimension(180, 40));
		lblCurrentStock.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[0]=lblCurrentStock;
		
		lblOutwardReport=new JLabel("Outward Report",SwingConstants.CENTER);
		lblOutwardReport.setPreferredSize(new Dimension(72, 40));
		lblOutwardReport.setMinimumSize(new Dimension(180, 40));
		lblOutwardReport.setMaximumSize(new Dimension(180, 40));
		lblOutwardReport.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[1]=lblOutwardReport;
		
		lblInwardReport=new JLabel("Inward Report",SwingConstants.CENTER);
		lblInwardReport.setPreferredSize(new Dimension(72, 40));
		lblInwardReport.setMinimumSize(new Dimension(180, 40));
		lblInwardReport.setMaximumSize(new Dimension(180, 40));
		lblInwardReport.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[2]=lblInwardReport;
		
		for(int k=0;k<leftMenu.length;k++)
			leftMenu[k].setBorder(null);
	}
	
	
	private void addButtonsInToolBar()
	{
		toolBar.add(lblCurrentStock);
		toolBar.addSeparator();
		toolBar.add(lblOutwardReport);
		toolBar.addSeparator();
		toolBar.add(lblInwardReport);
		toolBar.addSeparator();
	}
	
	private void addButtonListener()
	{
		for(JLabel temp:this.leftMenu)
			 temp.addMouseListener(this);
	}
	
	@Override
	public void mouseClicked(MouseEvent arg0) 
	{
		if(arg0.getSource() instanceof JLabel)
		{
			JLabel label=(JLabel) arg0.getSource();
			
			if(label==lblCurrentStock)
			{
				CurrentStockReportView csrv=new CurrentStockReportView();
				CurrentStockReportController cntrl=new CurrentStockReportController(csrv);
				UIFrameWork.setReportComponent(sl, csrv, this,2);
			}
				
			if(label==lblInwardReport)
			{
				InwardReportView irv=new InwardReportView();
				InwardReportController incntrl=new InwardReportController(irv);
				UIFrameWork.setReportComponent(sl, irv, this,2);
			}
			
			if(label==lblOutwardReport)
			{
				OutwardReportView orv=new OutwardReportView();
				OutwardReportController outcntrl=new OutwardReportController(orv);
				UIFrameWork.setReportComponent(sl, orv, this,2);
			}
		}
	}


	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
}
